using System.Collections.Generic;

public class ZeroMemoryReleaseList<T>
{
	private List<T> list = new List<T>();

	public int Count { get; protected set; }

	public T this[int index]
	{
		get
		{
			return list[index];
		}
		set
		{
			list[index] = value;
		}
	}

	public void Clear()
	{
		Count = 0;
	}

	public void Add(T item)
	{
		Count++;
		if (Count > list.Count)
		{
			list.Add(item);
		}
		else
		{
			list[Count - 1] = item;
		}
	}

	public void Sort(IComparer<T> comparer)
	{
		list.Sort(0, Count, comparer);
	}
}
